#!/usr/bin/env python
#author : sixther.me
#date : 2014-09-20
import sys
import os

host=sys.argv[1]
port=sys.argv[2]
key_dick={}

cmd='memcache-tool ' + host + ':' + port + ' stats'
for i in  os.popen(cmd):
        key=i.split()[0].strip()
        value=i.split()[1].strip()
        key_dick[key]=value

def get_curr_connections():
        return float(key_dick['curr_connections'])
def get_hit_ratio():
        hit_ratio=float(key_dick['get_hits'])/float(key_dick['cmd_get']) * 100.00
        return hit_ratio
def get_rps():
        return float(key_dick['cmd_get'])
def get_wps():
        return float(key_dick['cmd_set'])
def get_usage():
        usage=float(key_dick['bytes'])/float(key_dick['limit_maxbytes']) * 100.00
        return usage
if __name__ == '__main__':
        status_data_array={
                'curr_connections':'get_curr_connections()',
                'hit_ratio':'get_hit_ratio()',
                'rps':'get_rps()',
                'wps':'get_wps()',
                'usage':'get_usage()'
        }
        print "%.2f" % eval(status_data_array[sys.argv[3]])
